package jp.sinmetal.trainer.entity;

import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Version;

import org.seasar.framework.beans.util.Beans;


/**
 * 大会参加者エンティティ
 * @author sin
 *
 */
@Entity
@Table(name="convention_member")
public class ConventionMember extends AbstractEntity {

    /**
     * 大会参加者ID
     * @author sin
     */
    @Id
    @GeneratedValue
    @Column(name="convention_member_id")
    public Integer conventionMemberId;

    /**
     * 大会ID
     * @author sin
     */
    @Column(name="convention_id")
    public Integer conventionId;

    /**
     * 大会参加者メンバーID
     * @author sin
     */
    @Column(name="member_id")
    public Integer memberId;

    /**
     * 対戦数
     * @author sin
     */
    @Column(name="battle_count")
    public Integer battleCount;

    /**
     * 勝利数
     * @author sin
     */
    @Column(name="win_count")
    public Integer winCount;

    /**
     * 最終勝利日時
     * @author sin
     */
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="win_date")
    public Date winDate;

    /**
     * アクティブフラグ
     * @author sin
     */
    @Column(name="active_flag")
    public Boolean activeFlag;

    /**
     * 対戦中フラグ
     * @author sin
     */
    @Column(name="battle_flag")
    public Boolean battleFlag;

    /**
     * 承認フラグ
     * @author sin
     */
    @Column(name="accept_flag")
    public Boolean acceptFlag;

    /**
     * 登録日
     * @author sin
     */
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="entry_date")
    public Date entryDate;

    /**
     * 更新日
     * @author sin
     */
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name="update_date")
    public Date updateDate;

    /**
     * バージョン
     * @author sin
     */
    @Version
    public Long version;

    //----------- s2jdbc連結定義 ----------

    /**
     * 大会
     * @author sin
     */
    @ManyToOne
    @JoinColumn(name="convention_id", referencedColumnName="convention_id")
    public Convention convention;

    /**
     * 大会参加者
     * @author sin
     */
    @ManyToOne
    @JoinColumn(name="member_id", referencedColumnName="member_id")
    public Member member;

    /**
     * 大会ログ1st一覧
     * @author sin
     */
    @OneToMany(mappedBy="conventionMember1st")
    public List<ConventionLog> conventionLog1sts;

    /**
     * 大会ログ2st一覧
     * @author sin
     */
    @OneToMany(mappedBy="conventionMember2nd")
    public List<ConventionLog> conventionLog2sts;

    /**
     * 勝利者一覧
     * @author sin
     */
    @OneToMany(mappedBy="winConventionMember")
    public List<ConventionLog> winConventionLog;

    //---------- ----------

    /**
     * ConventionMemberのインスタンスを返す
     * @param form
     * @return
     */
    public static ConventionMember getInstance(Object form) {
    	return Beans.createAndCopy(ConventionMember.class, form).dateConverter(DATE_FORMAT).execute();
    }

}